import React, { Component, lazy, Suspense } from "react";

import { Link, Route, Switch } from "react-router-dom";

// import Home from "./Home";
// import Share from "./Share";

const Home = lazy(() => import("./Home"));
const Share = lazy(() => import("./Share"));

class App extends Component {
  render() {
    return (
      <>
        <h2>路由懒加载</h2>
        <ul>
          <li>
            <Link to="/home">首页</Link>
          </li>
          <li>
            <Link to="/share">分享页</Link>
          </li>
        </ul>

        <hr />

        <Switch>
          <Route path="/home">
            <Suspense fallback={<div>loading...</div>}>
              <Home />
            </Suspense>
          </Route>
          <Route path="/share">
            <Suspense fallback={<div>loading...</div>}>
              <Share />
            </Suspense>
          </Route>
        </Switch>
      </>
    );
  }
}

export default App;
